from bs4 import BeautifulSoup
import requests

URL_BAIDU_NEWS_PATH = 'http://news.baidu.com/'

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
    "Accept-Language": "zh-CN,zh;q=0.8",
    "Connection": "close",
    "Cookie": "_gauges_unique_hour=1; _gauges_unique_day=1; _gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1",
    "Referer": "http://www.infoq.com",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER"
}

url = URL_BAIDU_NEWS_PATH


def craw_news(url):
    response = requests.get(url, headers=headers)

    soup = BeautifulSoup(response.text, 'lxml')

    title_href = soup.find('div', class_='hotnews')

    for title in title_href.find_all('a', {'target':'_blank'}):
         print(title.get_text())

    # 金色相框｜习近平给您拜年
    # 【央视快评】看中华儿女走向新的天地
    # 2019
    # 央视春晚“追梦人”开启执着奋斗幸福年
    # 【春晚揭秘】《"儿子"
    # 来了》:当蔡明遇到葛优
    # 网络大过年
    # 在全社会大力弘扬家国情怀
    # 新春走基层
    # 小辣椒奏响“新乐章”


craw_news(url)


